{% extends 'base.html' %}
{% block title %}登录{% endblock %}
{% block head %}
<link rel="stylesheet" href="{{ url_for('static',filename='css/base1.css') }}">
{% endblock %}
{% block main %}

<div class="form-container">
<h3 class="page-title">登录</h3>
  <div class="form-group">
    <input type="text" name="login_name" class="form-control" onclick="click_name()" id="box_name" placeholder="请输入账号">
  </div>
  <div class="form-group">
    <input type="password" name="login_password" class="form-control" onclick="click_name()" id="box_pass" placeholder="请输入密码">
  </div>
    <div id="search_pass_link">
        <label id="message" style="color: red;"></label><a href="#" style="float: right" >忘记密码？</a>
    </div>
{#    文件的#}
{#  <div class="form-group">#}
{#    <label for="exampleInputFile">File input</label>#}
{#    <input type="file" id="exampleInputFile">#}
{#    <p class="help-block">Example block-level help text here.</p>#}
{#  </div>#}
  <div class="checkbox">
    <label>
      <input type="checkbox" id="checkbox" onclick="button_check()"/> <a href="#">同意各种丧尽天良的合同</a>
    </label>
  </div>
{#  <button type="submit" class="btn btn-default btn-block">提交</button>#}
    <div class="sumbit" >
    <button type="submit" class="btn btn-default disabled" id="submit" onclick="login()">提交</button>
        <button type="button" class="btn btn-default" onclick="click_register()">注册</button>
        </div>
</div>
{% endblock %}
{% block jsna %}
<script>
        //注册
        function click_register() {
             window.location.href="/register";
        }
        // 登录
        function login() {
            var username = document.getElementById('box_name').value;
            var password = document.getElementById('box_pass').value;
            $.ajax({
                headers: {"X-CSRFToken": '{{ csrf_token }}'},
                url: "/login/login_check/",
                type: 'POST',
                tradition: true,
                dataType: 'json',
                data: {'username': username, 'password': password},
                success: function (data) {
                    if (data.state == 'success') {
                        document.getElementById("message").innerHTML = '登录成功'
                        window.location.href = data.url
                    } else if (data.state == 'fail') {
                        $('#message').html(data.message)
                        setTimeout(function () {
                            $('#message').html('');
                            document.getElementById("box_name").value = '';
                            document.getElementById("box_pass").value = '';
                        }, 3000)
                    }
                }
            })
        }
        function button_check() {
            var name1=document.getElementById("checkbox");
            if (name1.checked == true){
                document.getElementById("submit").className = 'btn btn-default';
            }else{
                document.getElementById("submit").className = 'btn btn-default disabled';
            }


        }
</script>
{% endblock %}